<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script src="js/jquery.js"></script>
    <script src="js/layer/layer.js"></script>
    <script src="js/config.js"></script>
</head>
<body>
<table>
    <tr>
        <td>用户名</td>
        <td>
            <input type="text" id="user_name">
        </td>
    </tr>
    <tr>
        <td>密码</td>
        <td>
            <input type="text" id="password">
        </td>
    </tr>
    <tr>
        <td>
            <input type="button" value="确定" id="do_reg">
        </td>
        <td>
            <input type="button" value="取消" id="back">
        </td>
    </tr>
</table>
</body>
</html>
<script>

    $("#do_reg").click(function () {
        var user_name = $("#user_name").val();
        var password = $("#password").val();
        $.ajax({
            url:api_host + "/user/reg",
            type:'post',
            data:{user_name:user_name,password:password},
            dataType:'json',
            success:function (data) {
                console.log(data);
                if (data.code == 1) {
                    window.localStorage.setItem('token',data.token);
                    window.location.href = 'index.html';
                } else {
                    layer.alert(data.msg);
                }
            },
            error:function () {
                layer.alert('网络错误');
            }
        });
    });

    $("#back").click(function () {
        window.location.href = 'login.html';
    });
</script>